﻿using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Utilities;
using UnityEngine;


#if UNITY_EDITOR
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities.Editor;
#endif
namespace Gp.Scripts.Data {
    [Serializable]
    public class UnitInventory {
        [HideLabel] [ListDrawerSettings(CustomAddFunction = "AddSlot")]
        public List<int> slots = new();


        public void CopyFrom(UnitInventory other) {
            slots.Clear();
            slots.AddRange(other.slots);
        }


        // public void Add(InventoryConfigObject item) {
        //     if (item == null) return;
        //     slots.Add(new ItemSlot() {
        //         item = item,
        //         itemCount = 1
        //     });
        // }
        
// #if UNITY_EDITOR
//         private ItemSlot AddSlot() {
//             return new ItemSlot() {
//                 itemCount = 1
//             };
//         }
// #endif
    }


    // [Serializable]
    // [HideLabel]
    // public struct ItemSlot {
    //     [HideLabel] [HorizontalGroup("Item")] public InventoryConfigObject item;
    //
    //     [LabelText("数量")] [VerticalGroup("Item/Count")] [MinValue(1)]
    //     public int itemCount;
    // }
    //
    
    
#if UNITY_EDITOR
    public class UnitInventoryDrawer : OdinValueDrawer<UnitInventory> {
        protected override void DrawPropertyLayout(GUIContent label) {
            CallNextDrawer(label);

            GUILayout.Label("拖动到此处添加库存");
            var rect = GUILayoutUtility.GetRect(0, 40).Padding(2);
            var id = DragAndDropUtilities.GetDragAndDropId(rect);


            DragAndDropUtilities.DrawDropZone(rect, null as UnityEngine.Object, null, id);
            
            // var obj = DragAndDropUtilities.DropZone<InventoryConfigObject>(rect, null, false, id);
            // if (obj == null) return;
            // this.ValueEntry.SmartValue.slots.Add(new ItemSlot() {
            //     itemCount = 1,
            //     item = obj
            // });
        }
    }
#endif
}